<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form">
        <div>
          <a-steps :current="current">
            <a-step v-for="item in steps" :key="item.title" :title="item.title">
              <a-icon slot="icon" :type="item.iconType" />
              <span style="color:#00DB00;" slot="description">{{item.description}}</span>
            </a-step>
          </a-steps>
          <div class="steps-content" style="" >
            <template   >
              <a-col :sm="12" v-show="current == 0" style="width:1000px">
                <!-- <j-dict-select-tag  type="radio" @change="onChangeType" v-model="type" dictCode="work_flow_type" placeholder="请选择交收类型" />-->

                <label>
                  <a-tag color="#f50" style="font-weight: bold;font-size: 16px;margin-left: 211px">
                    入库类：
                  </a-tag>
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="1" v-model="type"> 公司购石</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="2" v-model="type"> 客来石</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="3" v-model="type"> 收发回石</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="4" v-model="type"> 镶石退库</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="19" v-model="type"> 失石找回</label>

                  <br/>
                  <a-tag color="#2db7f5" style="font-weight: bold;font-size: 16px;margin-left: 100px">
                    出库类：
                  </a-tag>
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="11" v-model="type"> 公司卖石</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="12" v-model="type"> 退购石</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="13" v-model="type"> 退客石</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="14" v-model="type"> 配石到收发</label>
                  <br/>
                  <a-tag color="#2db7f5" style="font-weight: bold;font-size: 16px;margin-left: 100px">
                    出库类：
                  </a-tag>
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="15" v-model="type"> 补石出库</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="16" v-model="type"> 换烂石</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="17" v-model="type"> 补失石</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="18" v-model="type"> 烂失石登记</label>
                </label>
              </a-col>
            </template>
            <template>
              <a-col v-show="current == 1 && (this.type == 1 || this.type == 2)" style="padding-left: 200px;padding-top: 60px;">
                <a-form-model-item label="发出客户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendCustomer">
                  <j-dict-select-tag ref="sendCustomer" style="width: 300px;margin-left: -300px;font-size:16px"  @change="onChangeSendInfo(3)" v-model="sendCustomer" placeholder="请选择发出客户" dictCode="customer_info,cus_name,id"/>
                </a-form-model-item>
              </a-col>
              <a-col v-show="current == 1 && (this.type == 3 || this.type == 4 || this.type == 19)" style="padding-left: 200px;padding-top: 60px">
                <a-form-model-item label="发出员工"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendPerson">
                  <j-select-user-by-dep @change="onChangeSendInfo(1)"  style="width: 200px;margin-left: 10px;font-size:16px" ref="sendPerson" placeholder="请选择发出员工" :multi="false" v-model="sendPerson"/>
                </a-form-model-item>
              </a-col>
              <a-col v-show="current == 1 && (this.type == 11 || this.type == 12 || this.type == 13 || this.type == 14 || this.type == 15 || this.type == 16 || this.type == 17 || this.type == 18)" style="padding-left: 100px;padding-top: 60px">
                <a-form-model-item label="发出仓库"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendStorage">
                  <j-dict-select-tag @change="onChangeSendInfo(2)" ref="sendStorage" v-model="sendStorage" style="width: 300px;margin-left: -400px;font-size:16px" placeholder="请选择发出仓库" dictCode="stone_storage,name,id"/>
                </a-form-model-item>
              </a-col>
            </template>
            <template >
              <a-col v-show="current == 2 && (this.type == 1 || this.type == 2 || this.type == 3 || this.type == 4 || this.type == 19)" style="padding-left: 100px;padding-top: 60px">
                <a-form-model-item label="接收仓库" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveStorage">
                  <j-dict-select-tag @change="onChangeReceiveInfo(2)" ref="receiveStorage" v-model="receiveStorage" style="width: 300px;margin-left: -400px;font-size:16px" placeholder="请选择接收仓库" dictCode="stone_storage,name,id"/>
                </a-form-model-item>
              </a-col>

              <a-col v-show="current == 2 && (this.type == 11 || this.type == 12 || this.type == 13)">
                <a-form-model-item style="padding-left: 200px;padding-top: 40px" label="接收客户"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveCustomer">
                  <j-dict-select-tag ref="receiveCustomer" style="width: 220px;margin-left: -400px"
                                     @change="onChangeReceiveInfo(3)" v-model="receiveCustomer"
                                     placeholder="请选择接收客户" dictCode="customer_info,cus_name,id"/>
                </a-form-model-item>
              </a-col>

              <a-col v-show="current == 2 && (this.type == 14 || this.type == 15 || this.type == 16 || this.type == 17 || this.type == 18)" style="padding-left: 200px;padding-top: 60px">
                <a-form-model-item label="接收员工"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receivePerson">
                  <j-select-user-by-dep @change="onChangeReceiveInfo(1)" style="width: 200px;margin-left: 10px" placeholder="请选择接收员工" :multi="false" v-model="receivePerson"/>
                </a-form-model-item>
              </a-col>

            </template>
            <template >
              <div v-show="current == 3">
                <j-editable-table
                  ref="editableTable"
                  :loading="loading"
                  :columns="columns"
                  :dataSource="dataSource"
                  :rowNumber="true"
                  :rowSelection="showRowSelection"
                  :actionButton="showActionButton"
                  :dragSort="showDragSort"
                  :scroll="{x:true,y:true}"
                  style="margin: 2px 2px 3px 3px"
                  @valueChange="handleValueChange"
                  @selectRowChange="handleSelectRowChange">

                  <template v-slot:action="props">
                    <a @click="handleDelete(props)">删除</a>
                  </template>
                  <template slot="picSlot" slot-scope="text, record">
                    <span v-for="(item,index) in (text|| '').split(',')">
                      <span v-if="item">
                        <img  :src="getImgView(item)" :preview="item" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
                        <a-divider type="vertical" />
                      </span>
                      <span v-else style="font-size: 12px;font-style: italic;">无图片</span>
                    </span>
                  </template>
                </j-editable-table>
              </div>

              <div>{{tips}}</div>
            </template>
          </div>
          <div class="steps-action">
            <a-button :disabled="current == 0" @click="prev">
              上一步
            </a-button>
            <!--<a-button style="margin-left: 8px"
              v-if="current == steps.length - 1"
              type="primary"
              @click="$message.success('完成!')"
            >
              完成
            </a-button>-->
            <a-button :disabled="current == (steps.length - 1)" ref="nextBtn" style="margin-left: 8px" type="primary" @click="next">
              下一步
            </a-button>
          </div>
        </div>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>
<script>
  import moment from 'moment'
  import { getAction, postAction } from '@/api/manage'
  import { FormTypes } from '@/utils/JEditableTableUtil'
  import { randomUUID, randomNumber } from '@/utils/util'
  import JEditableTable from '@/components/jeecg/JEditableTable'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JTreeSelect from '@/components/jeecg/JTreeSelect'

  export default {
    components: { JEditableTable,JSelectDepart,JTreeSelect },
    data() {
      return {
        title: '石出入库',
        width:1200,
        visible: false,
        confirmLoading: false,
        tips:'',
        form1: this.$form.createForm(this),
        current: 0,
        steps: [
          {
            title: '操作类型',
            content: 'First-content',
            iconType: 'appstore',
            description: ''
          },
          {
            title: '发出方',
            content: 'Second-content',
            iconType: 'user-delete',
            description: ''
          },
          {
            title: '接收方',
            content: 'Third-content',
            iconType: 'user-add',
            description: ''
          },
          {
            title: '确认',
            content: 'Fourth-content',
            iconType: 'form',
            description: ''
          }
          // {
          //   title: '完成',
          //  content: 'Last-content',
          //  iconType: 'check'
          //  },
        ],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        showRowSelection: true,
        showActionButton: true,
        showDragSort: true,
        type: '',
        sendPerson: '',
        sendStorage: '',
        sendCustomer: '',
        receivePerson: '',
        receiveStorage: '',
        receiveCustomer: '',
        sendByName:'',//提示语
        receiveByName:'',//提示语
        loading: false,
        columns: [
          {
            title: '采购单号',
            key: 'purchaseOrderNum',
            width: '100px',
            type: FormTypes.input,
          },{
            title: '批号',
            key: 'batchNum',
            width: '100px',
            type: FormTypes.input,
          },{
            title: '来单号',
            key: 'receiveOrderNum',
            width: '100px',
            type: FormTypes.input,
          },{
            title: '工单号',
            key: 'workNum',
            width: '100px',
            type: FormTypes.input,
          },{
            title: '拆分页',
            key: 'pn',
            width: '100px',
            type: FormTypes.input,
          },
          {
            title: '石卡号',
            key: 'codeNum',
            width: '130px',
            type: FormTypes.input,
            disabled:true
          },{
            title: '石号',
            key: 'stoneNum',
            width: '130px',
            type: FormTypes.popup,
            popupCode: 'stone_style_report',
            orgFields: 'stone_code_num',
            destFields: 'stoneNum',
            field:'stoneNum'
          },{
            title: '好石数',
            key: 'goodStoneCount',
            width: '100px',
            type: FormTypes.input,
          },{
            title: '好石重',
            key: 'goodStoneWeight',
            width: '100px',
            type: FormTypes.input
          },{
            title: '坏石数',
            key: 'badStoneCount',
            width: '100px',
            type: FormTypes.input
          },{
            title: '坏石重',
            key: 'badStoneWeight',
            width: '100px',
            type: FormTypes.input
          },{
            title: '石号名称',
            key: 'stoneName',
            width: '100px',
            type: FormTypes.input,
            disabled:true
          },{
            title: '石类',
            key: 'cateId',
            width: '100px',
            type: FormTypes.select,
            dictCode:'stone_category,cate_name,id',
            disabled:true
          },{
            title: '单粒重',
            key: 'weight',
            width: '100px',
            type: FormTypes.input,
            disabled:true
          },{
            title: '筛号',
            key: 'sizeNum',
            width: '100px',
            type: FormTypes.input,
            disabled:true
          },{
            title: '级别',
            key: 'level',
            width: '170px',
            type: FormTypes.select,
            dictCode:'stone_level',
            disabled:true
          },{
            title: '形状',
            key: 'shape',
            width: '100px',
            type: FormTypes.select,
            dictCode:'shape',
            disabled:true
          },{
            title: '规格',
            key: 'style',
            width: '100px',
            type: FormTypes.select,
            dictCode:'stone_style',
            disabled:true
          },{
            title: '净度',
            key: 'neatness',
            width: '100px',
            type: FormTypes.select,
            dictCode:'stone_clarity',
            disabled:true
          },{
            title: '车工',
            key: 'cutting',
            width: '120px',
            type: FormTypes.select,
            dictCode:'cutting',
            disabled:true
          },{
            title: '颜色',
            key: 'color',
            width: '100px',
            type: FormTypes.select,
            dictCode:'color',
            disabled:true
          },{
            title: '质地',
            key: 'texture',
            width: '100px',
            type: FormTypes.select,
            dictCode:'texture',
            disabled:true
          },{
            title: '角度',
            key: 'angle',
            width: '100px',
            type: FormTypes.input,
            disabled:true
          },{
            title: '主副石',
            key: 'mainStone',
            width: '100px',
            type: FormTypes.select,
            dictCode:'main_stone_type',
          },{
            title: '镶法',
            key: 'inlay',
            width: '100px',
            type: FormTypes.select,
            dictCode:'inlay_type',
          },{
            title: '成本单价',
            key: 'stoneUnitCost',
            width: '100px',
            type: FormTypes.input,
            disabled:true
          },{
            title: '单价',
            key: 'stoneUnitPrice',
            width: '100px',
            type: FormTypes.input,
            disabled:true
          },{
            title: '发票类型',
            key: 'invoiceType',
            width: '120px',
            type: FormTypes.select,
            dictCode:'invoice_type',
          },{
            title: '实际币种',
            key: 'currencyType',
            width: '120px',
            type: FormTypes.select,
            dictCode:'currency_type',
          },{
            title: '实际单价',
            key: 'stoneUnitPlay',
            width: '100px',
            type: FormTypes.input,
          },{
            title: '实际金额',
            key: 'stoneCost',
            width: '100px',
            type: FormTypes.input,
          },{
            title: '汇率',
            key: 'exchangeRate',
            width: '100px',
            type: FormTypes.input,
          },{
            title: '计价方式',
            key: 'countPricePattern',
            width: '100px',
            type: FormTypes.select,
            dictCode:'count_price_pattern',
            disabled:true
          },{
            title: '备注',
            key: 'remark',
            width: '100px',
            type: FormTypes.input,
          },
        ],
        dataSource: [],
        selectedRowIds: [],
        url: {
          getPerson : "/stoneEntry/getPerson",
          getStorage : "/stoneEntry/getStorage",
          getCustomer : "/stoneEntry/getCustomer"
        }
      };
    },
    computed: {
    },
    mounted() {
      // this.initData(false)
    },
    //自动触发点击事件
    watch:{
      type(newVal,oldVal){
        if(newVal !='' && newVal !== oldVal) {
          this.$refs.nextBtn.$emit('click')
        }
      },
      sendPerson(newVal,oldVal){
        if(newVal !='' && newVal !== oldVal) {
          this.$refs.nextBtn.$emit('click')
        }
      },
      sendCustomer(newVal,oldVal){
        if(newVal !='' && newVal !== oldVal) {
          this.$refs.nextBtn.$emit('click')
        }
      },
      sendStorage(newVal,oldVal){
        if(newVal !='' && newVal !== oldVal) {
          this.$refs.nextBtn.$emit('click')
        }
      },
      receivePerson(newVal,oldVal){
        if(newVal !='' && newVal !== oldVal) {
          this.$refs.nextBtn.$emit('click')
        }
      },
      receiveCustomer(newVal,oldVal){
        if(newVal !='' && newVal !== oldVal) {
          this.$refs.nextBtn.$emit('click')
        }
      },
      receiveStorage(newVal,oldVal){
        if(newVal !='' && newVal !== oldVal) {
          this.$refs.nextBtn.$emit('click')
        }
      }
    },
    methods: {
      initStorageData(url,params) {//初始化仓库库存数据
        this.showRowSelection = true
        this.showActionButton = false
        this.showDragSort = false
        let that = this
        getAction(url,params).then((res)=>{
          if(res.success){
            let size = res.result.length
            let values = []
            for (let i = 0; i < size; i++) {
              let idStr = randomUUID()
              values.push(
                {
                  id: idStr,
                  stoneName: res.result[i].stoneName,
                  purchaseOrderNum: '',
                  codeNum: res.result[i].codeNum,
                  stoneNum: res.result[i].stoneNum,
                  cateId: res.result[i].cateId,
                  sizeNum: res.result[i].sizeNum,
                  level: res.result[i].level,
                  shape: res.result[i].shape,
                  style: res.result[i].style,
                  neatness: res.result[i].neatness,
                  cutting: res.result[i].cutting,
                  color: res.result[i].color,
                  texture: res.result[i].texture,
                  angle: res.result[i].angle,
                  weight: res.result[i].weight,
                  goodStoneCount: res.result[i].goodStoneCount,
                  goodStoneWeight: res.result[i].goodStoneWeight,
                  badStoneCount: res.result[i].badStoneCount,
                  badStoneWeight: res.result[i].badStoneWeight,
                  inlay: res.result[i].inlay,
                  stoneUnitCost: '',
                  stoneUnitPrice: '',
                  batchNum: '',
                  receiveOrderNum: '',
                  mainStone: '',
                  invoiceType: '',
                  currencyType: '',
                  stoneUnitPlay: '',
                  stoneCost: res.result[i].stoneCost,
                  exchangeRate: '',
                  countPricePattern: res.result[i].countPricePattern,
                  remark: ''
                }
              )
            }
            that.dataSource = values
          }else{
            that.$message.warning(res.message);
          }
        })
      },
      getFormFieldValue(field){
        return this.form1.getFieldValue(field)
      },
      next() {
        if(this.current == 0) {
          if(this.type == '') {
            this.$message.warning('请先选择操作类型！');
            return
          }
          this.current++;
        }
        if(this.current == "1") {//发出方
          if(this.type == 1 || this.type == 2){//发出方是客户
            if(this.sendCustomer == null || this.sendCustomer == ''){
              //this.$message.warning('请选择发出客户')
              return
            }
            this.current++;
          } else if (this.type == 3 || this.type == 4 || this.type == 19) {//发出方是员工
            if(this.sendPerson == null || this.sendPerson == ''){
              //this.$message.warning('请选择发出员工')
              return
            }
            this.current++;
          } else if (this.type == 11 || this.type == 12 || this.type == 13 || this.type == 14 || this.type == 15 || this.type == 16 || this.type == 17 || this.type == 18) {//发出方是仓库
            if(this.sendStorage == null || this.sendStorage == ''){
              //this.$message.warning('请选择发出仓库')
              return
            }
            this.current++;
          }
        }else if(this.current == "2") {//接收方
          if (this.type == 1 || this.type == 2 || this.type == 3 || this.type == 4 || this.type == 19) {//接收仓库
            if(this.receiveStorage == null || this.receiveStorage == ''){
              //this.$message.warning('请选择接收仓库')
              return
            }
            this.current++;
          } else if (this.type == 11 || this.type == 12 || this.type == 13) {//接收客户
            if(this.receiveCustomer == null || this.receiveCustomer == ''){
              //this.$message.warning('请选择接收客户')
              return
            }
            this.current++;
          } else if (this.type == 14 || this.type == 15 || this.type == 16 || this.type == 17 || this.type == 18) {//接收员工
            if(this.receivePerson == null || this.receivePerson == ''){
              //this.$message.warning('请选择接收员工')
              return
            }
            this.current++;
          }
        }
        if(this.current == "3") {//确认
            if(this.type == 11 || this.type == 12 || this.type == 13 || this.type == 14 || this.type == 15 || this.type == 16 || this.type == 17 || this.type == 18){//当进行跟库存数据有关的操作类型时，要将库存数据列表显示出来
              let params = {
                storageId: this.sendStorage
              }
              this.initStorageData("/stoneEntry/queryStorageData",params)
            } else if(this.type == 3 || this.type == 4 || this.type == 19){//员工移交金，库存在员工身上
              let params = {
                userId: this.sendPerson
              }
              this.initStorageData("/stoneEntry/queryPersonData",params)
            }
        }
      },
      prev() {
        this.current--;
      },
      init () {
        this.visible = true
      },
      handleValueChange(event) {
        const { type, row, column, value, target } = event
        if (type === FormTypes.input) {
         if (column.key == 'stoneNum') {
            target.setValues([{
              rowKey: row.id,
              values: { stoneNum: value}
            }])
            // if(value != null && value != '' && value.length >= 4){
            let params = {
              stoneNum : value
            }
            getAction("/stoneEntry/queryStoneStyleByStoneNum",params).then(res=>{
              if(res.success){
                target.setValues([{
                  rowKey: row.id,
                  values: { stoneName: res.result.name}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { stoneNum: res.result.code_num}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { cateId: res.result.cate_id}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { sizeNum: res.result.size_num}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { level: res.result.level}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { shape: res.result.shape}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { style: res.result.style}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { neatness: res.result.neatness}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { cutting: res.result.cutting}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { color: res.result.color}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { texture: res.result.texture}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { angle: res.result.angle}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { weight: res.result.weight}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { stoneUnitPrice: res.result.price}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { stoneUnitCost: res.result.cost_price}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { inlay: res.result.inlay}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { countPricePattern: res.result.count_price_pattern}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { remark: res.result.remark}
                }])
              }
            })
            //}
          } else if (column.key == 'weight') {
            target.setValues([{
              rowKey: row.id,
              values: { weight: value}
            }])
          } else if (column.key == 'goodStoneCount') {
            target.setValues([{
              rowKey: row.id,
              values: { goodStoneCount: value}
            }])
          } else {
            return
          }
        }
        let goodStoneWeightVal = (row.goodStoneCount * row.weight).toFixed(2)
        target.setValues([{
          rowKey: row.id,
          values: { goodStoneWeight: goodStoneWeightVal }
        }])
      },
      onChangeSendInfo(type) {
        if(type == 1){//发出类型是员工
          if(this.sendPerson == ''){
            this.steps[this.current].description = ''
            return
          }
          let params = {
            username: this.sendPerson
          }
          getAction(this.url.getPerson,params).then((res)=>{
            if(res.success){
              this.steps[this.current - 1].description = res.result
            }
          })
        } else if (type == 2) {//发出类型是仓库
          if(this.sendStorage == ''){
            this.steps[this.current].description = ''
            return
          }
          let params = {
            id: this.sendStorage
          }
          getAction(this.url.getStorage,params).then((res)=>{
            if(res.success){
              this.steps[this.current - 1].description = res.result
            }
          })
        } else if (type == 3) {//发出类型是客户
          if(this.sendCustomer == ''){
            this.steps[this.current].description = ''
            return
          }
          let params = {
            id: this.sendCustomer
          }
          getAction(this.url.getCustomer,params).then((res)=>{
            if(res.success){
              this.steps[this.current - 1].description = res.result
            }
          })
        }
      },
      onChangeReceiveInfo(type) {
        if(type == 1){//接收类型是员工
          if(this.receivePerson == ''){
            this.steps[this.current].description = ''
            return
          }
          let params = {
            username: this.receivePerson
          }
          getAction(this.url.getPerson,params).then((res)=>{
            if(res.success){
              this.steps[this.current - 1].description = res.result
            }
          })
        } else if (type == 2) {//接收类型是仓库
          if(this.receiveStorage == ''){
            this.steps[this.current].description = ''
            return
          }
          let params = {
            id: this.receiveStorage
          }
          getAction(this.url.getStorage,params).then((res)=>{
            if(res.success){
              this.steps[this.current - 1].description = res.result
            }
          })
        } else if (type == 3) {//接收类型是客户
          if(this.receiveCustomer == ''){
            this.steps[this.current].description = ''
            return
          }
          let params = {
            id: this.receiveCustomer
          }
          getAction(this.url.getCustomer,params).then((res)=>{
            if(res.success){
              this.steps[this.current - 1].description = res.result
            }
          })
        }
      },
      onChangeType () {
        this.showActionButton = true
        this.steps[1].description = ''
        this.steps[2].description = ''
        this.sendPerson = ''
        this.sendStorage = ''
        this.sendCustomer = ''
        this.receivePerson = ''
        this.receiveStorage = ''
        if(this.type == 1) {//公司购石
          this.steps[0].description = '公司购石'
        } else if(this.type == 2) {//客来石
          this.steps[0].description = '客来石'
        } else if(this.type == 3) {//收发回石
          this.steps[0].description = '收发回石'
        } else if(this.type == 4) {//镶石退库
          this.steps[0].description = '镶石退库'
        } else if(this.type == 11) {//公司卖石
          this.steps[0].description = '公司卖石'
        } else if(this.type == 12) {//退购石
          this.steps[0].description = '退购石'
        } else if(this.type == 13) {//退客石
          this.steps[0].description = '退客石'
        } else if(this.type == 14) {//配石到收发
          this.steps[0].description = '配石到收发'
        } else if(this.type == 15) {//补石出库
          this.steps[0].description = '补石出库'
        } else if(this.type == 16) {//换烂石
          this.steps[0].description = '换烂石'
        } else if(this.type == 17) {//补失石
          this.steps[0].description = '补失石'
        } else if(this.type == 18) {//烂失石登记
          this.steps[0].description = '烂失石登记'
        } else if(this.type == 19) {//失石找回
          this.steps[0].description = '失石找回'
        }
      },
      close () {
        this.confirmLoading = false;
        this.$emit('ok')
        this.$refs.form.clearValidate()
        this.$refs.form.resetFields()
        Object.assign(this.$data, this.$options.data.call(this))
        this.visible = false
      },
      handleOk () {
        const that = this
        // 触发表单验证
       // this.$refs.form.validate(valid => {
         // if (valid) {
       //     that.confirmLoading = true;
      //    }
      //  });
        this.handleTableGet()
      },
      handleCancel () {
        this.close()
      },
      /** 表单验证 */
      handleTableCheck() {
        this.$refs.editableTable.getValues((error) => {
          if (error === 0) {
            this.$message.success('验证通过')
          } else {
            this.$message.error('验证未通过')
          }
        })
      },
      /** 获取值，忽略表单验证 */
      handleTableGet() {
        this.$refs.editableTable.getValues((error, values) => {
          console.log('values:', values)
          let params = {
            sendPerson: this.sendPerson,
            sendStorage: this.sendStorage,
            sendCustomer: this.sendCustomer,
            receivePerson: this.receivePerson,
            receiveStorage: this.receiveStorage,
            receiveCustomer: this.receiveCustomer,
            type: this.type,
            data : values
          }
          console.log(JSON.stringify(params)+"===params")
          postAction("/stoneEntry/batchAdd",params).then(res=>{
            if(res.success){
              this.$message.success(res.message)
              this.close()
            }else{
              this.$message.error(res.message)
            }
          })
        }, false, this.selectedRowIds)
        //console.log('deleteIds:', this.$refs.editableTable.getDeleteIds())

        //this.$message.info('获取值成功，请看控制台输出')

      },
      /** 模拟加载1000条数据 */
      handleTableSet() {
        this.randomData(1000, true)
      },
      handleSelectRowChange(selectedRowIds) {
        this.selectedRowIds = selectedRowIds
        /*this.dataSource.forEach((row) => {
          let rowId = row.id
          let index = this.selectedRowIds.indexOf(rowId)
          this.columns.forEach((column) => {
            if(index == -1) {
              column.disabled = true
            } else {
              column.disabled = false
            }
          });
        })*/
      },
      /* 随机生成数据 */
      randomData(size, loading = false) {
        if (loading) {
          this.loading = true
        }
        let randomDatetime = () => {
          let time = parseInt(randomNumber(1000, 9999999999999))
          return moment(new Date(time)).format('YYYY-MM-DD HH:mm:ss')
        }
        let begin = Date.now()
        let values = []
        for (let i = 0; i < size; i++) {
          values.push({
            id: randomUUID(),
            dbFieldName: `name_${i + 1}`,
            // dbFieldTxt: randomString(10),
            multipleSelect: ['string', ['int', 'double', 'boolean'][randomNumber(0, 2)]],
            dbFieldType: ['string', 'int', 'double', 'boolean'][randomNumber(0, 3)],
            dbLength: randomNumber(0, 233),
            datetime: randomDatetime(),
            isNull: ['Y', 'N'][randomNumber(0, 1)]
          })
        }
        this.dataSource = values
        let end = Date.now()
        let diff = end - begin

        if (loading && diff < size) {
          setTimeout(() => {
            this.loading = false
          }, size - diff)
        }
      },
      handleDelete(props) {
        let { rowId, target } = props
        target.removeRows(rowId)
      }
    },
  };
</script>
<style scoped>
  .steps-content {
    margin-top: 16px;
    border: 1px dashed #aaaaaa;
    border-radius: 6px;
    background-color: #fafafa;
    min-height: 300px;
    text-align: center;
    padding-top: 20px;
  }

  .steps-action {
    margin-top: 24px;
  }
</style>